package test7;

class Animal{
    protected String name;

    public Animal(String name) {
        this.name = name;
    }
}
//不是所有的动物都能飞，所以不能写到Animal中，如果写到另一个类中，也不行，因为一个类不能继承多个类
interface IFlying{

    void fly();
}
interface IRunning{
    void run();
}
interface ISwimming{
    void swing();
}

class Bird extends Animal implements IFlying{
    public Bird(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name+"正在飞");
    }
}

class Frog extends Animal implements IRunning,ISwimming{
    public Frog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }

    @Override
    public void swing() {
        System.out.println(this.name+"正在游泳");
    }
}
class Duck extends Animal implements IRunning,ISwimming,IFlying{
    public Duck(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name+"正在飞");
    }

    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }

    @Override
    public void swing() {
        System.out.println(this.name+"正在游泳");
    }
}
public class Demo7 {

    public static void runFunc(IRunning iRunning){
        iRunning.run();
    }


    public static void main(String[] args) {
        runFunc(new Duck("鸭子"));
        runFunc(new Frog("青蛙"));
    }
}
